﻿@model AntUnion.FrameWork.Model.Models.CrmUser
@{
    ViewData["Title"] = "Create";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , parentFrameIndex = parent.layer.getFrameIndex(window.name); //获取窗口索引;

            /**多语言初始化 */
            top.SetFormPageLanguage(layui);

            /* 监听提交 */
            form.on('submit(submit-form)', function (data) {
                var postData = {
                    "password": data.field.password,
                    "confirmPassword": data.field.confirmPassword,
                    "validCode": data.field.validCode
                };
                $.ajax({
                    type: "POST",
                    url: "/Personal/UpdatePassword",
                    data: postData, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            /**提示语弹框 */
                            top.ShowMessageByKey(layui, item.msg, 6, 1000, function () {
                                parent.layer.close(parentFrameIndex);
                                window.parent.location.reload();
                            });
                        } else {
                            /**提示语弹框 */
                            top.AlertByKey(layui, item.msg, 0, 1000);
                        }
                        layer.closeAll('loading');
                    }
                });
                return false;
            });

            $("#getValidCode").click(function (obj) {
                const validCode = $("#getValidCode")
                var i = 60
                var timer = setInterval(() => {
                    i--
                    validCode.attr("disabled", true)
                    validCode.text(i + "s")
                    if (i === 0) {
                        clearInterval(timer);
                        validCode.attr("disabled", false)
                        validCode.text("发送验证码")
                    }
                }, 1000)
                var email = $("#email").text()
                $.ajax({
                    type: "POST",
                    url: "/Login/SendValidateCode",
                    data: { email: email, type: 'updatePassword' }, // 你的formid
                    error: function (request) {
                        console.log("请求超时");
                    },
                    success: function (res) {
                        if (res.code == 0) {
                            top.ShowMessageByKey(layui, res.msg, 6, 1000);
                        } else {
                            top.ShowMessageByKey(layui, res.msg, 0, 1000);
                        }
                    }
                });
            });
        });
    </script>
}

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <form class="layui-form" action="" lay-filter="component-form-group">
                    <div class="layui-form-item editmail">
                        <i class="layui-icon layui-icon-email" style="font-size: 70px; color: #16baaa;"></i>
                        <div id="email">@Model.Email</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" name="userPwd" id="phone">密码</label>
                        <div class="layui-input-block">
                            <input type="password" placeholder="userPwd" class="layui-input" name="password">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" name="newPwd" id="newPwd">确认密码</label>
                        <div class="layui-input-block">
                            <input type="password" placeholder="newPwd" class="layui-input" name="confirmPassword">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" id="validCode">验证码</label>
                        <div class="layui-input-block" style="margin-right:120px;">
                            <input type="text" placeholder="validCode" class="layui-input" name="validCode" style="display:inline-block">
                        </div>
                        <button type="button" id="getValidCode" class="layui-btn validcode-btn" lay-event="getValidCode">获取验证码</button>
                    </div>
                    <div class="submit-btn">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button id="submitForm" class="layui-btn" lay-submit="" lay-filter="submit-form">立即提交</button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>